<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="form.projectName" style="width: 370px;" placeholder="请输入项目名称" />
          </el-form-item>
          <el-form-item label="造价" prop="cost">
            <el-input v-model.number="form.cost" :precision="3" style="width: 370px;" placeholder>
              <span>&nbsp;天</span>
            </el-input>
          </el-form-item>
          <el-form-item label="规模" prop="scale">
            <el-input v-model="form.scale" style="width: 370px;" placeholder="请输入规模" />
          </el-form-item>
          <el-form-item label="设计单位" prop="designOrganization">
            <el-input
              v-model="form.designOrganization"
              style="width: 370px;"
              placeholder="请输入设计单位"
            />
          </el-form-item>
          <el-form-item label="施工单位" prop="enforcementOrganization">
            <el-input
              v-model="form.enforcementOrganization"
              style="width: 370px;"
              placeholder="请输入施工单位"
            />
          </el-form-item>
          <el-form-item label="监理单位" prop="supervisorOrganization">
            <el-input
              v-model="form.supervisorOrganization"
              style="width: 370px;"
              placeholder="请输入监理单位"
            />
          </el-form-item>
          <el-form-item label="建设单位" prop="constructionOrganization">
            <el-input
              v-model="form.constructionOrganization"
              style="width: 370px;"
              placeholder="请输入建设单位"
            />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="form.status" filterable placeholder="请选择" style="width:98%">
              <el-option
                v-for="item in dict.project_init_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('projectName')" prop="projectName" label="项目名称" show-overflow-tooltip/>
        <el-table-column v-if="columns.visible('cost')" prop="cost" label="造价" />
        <el-table-column v-if="columns.visible('scale')" prop="scale" label="规模" />
        <el-table-column
          v-if="columns.visible('designOrganization')"
          prop="designOrganization"
          label="设计单位"
          show-overflow-tooltip
        />
        <el-table-column
          v-if="columns.visible('enforcementOrganization')"
          prop="enforcementOrganization"
          label="施工单位"
          show-overflow-tooltip
        />
        <el-table-column
          v-if="columns.visible('supervisorOrganization')"
          prop="supervisorOrganization"
          label="监理单位"
          show-overflow-tooltip
        />
        <el-table-column
          v-if="columns.visible('constructionOrganization')"
          prop="constructionOrganization"
          label="建设单位"
          show-overflow-tooltip
        />
        <el-table-column v-if="columns.visible('remark')" prop="remark" label="备注" show-overflow-tooltip/>
        <el-table-column v-if="columns.visible('status')" prop="status" label="状态">
          <template slot-scope="scope">{{ dict.label.project_init_status[scope.row.status] }}</template>
        </el-table-column>
        <el-table-column
          v-permission="['admin','projectInit:edit','projectInit:del']"
          label="操作"
          width="150px"
          align="center"
        >
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudProjectInit from '@/api/sapientialSite/projectInit'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({
  title: '项目信息',
  url: 'api/projectInit',
  sort: 'id,desc',
  crudMethod: { ...crudProjectInit }
})
const defaultForm = {
  id: null,
  projectName: null,
  status: null,
  cost: null,
  scale: null,
  designOrganization: null,
  enforcementOrganization: null,
  supervisorOrganization: null,
  constructionOrganization: null,
  remark: null,
  isDelete: null,
  createUser: null,
  createDate: null,
  updateUser: null,
  updateDate: null
}
export default {
  name: 'ProjectInit',
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  // 数据字典
  dicts: ['project_init_status'],
  data() {
    return {
      permission: {
        add: ['admin', 'projectInit:add'],
        edit: ['admin', 'projectInit:edit'],
        del: ['admin', 'projectInit:del']
      },
      rules: {
        projectName: [
          { required: true, message: '请输入项目名称', trigger: 'blur' }
        ],
        cost: [{ required: true, message: '请输入造价', trigger: 'blur' }],
        scale: [{ required: true, message: '请输入规模', trigger: 'blur' }],
        designOrganization: [
          { required: true, message: '请输入设计单位', trigger: 'blur' }
        ],
        enforcementOrganization: [
          { required: true, message: '请输入施工单位', trigger: 'blur' }
        ],
        supervisorOrganization: [
          { required: true, message: '请输入监理单位', trigger: 'blur' }
        ],
        constructionOrganization: [
          { required: true, message: '请输入设计单位', trigger: 'blur' }
        ],
        status: [{ required: true, message: '请选择状态', trigger: 'blur' }]
      }
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      this.crud.params = {}
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    },
    number() {}
  }
}
</script>

<style scoped>
</style>
